<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>商品批量定价</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/input1.css"/>
	<script type="text/javascript">
		$(function(){
		    
		    $('#station').combobox({
				valueField:'station_id', //值字段
				textField:'station_name', //显示的字段
				url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1',
				onLoadSuccess : function(data) {
		            $('#station').combobox("setValue",-1);
	        	}
	        });
		   
			loadTable();
			$('#dlg').dialog('close');
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
		 		url:'${pageContext.request.contextPath }/goods/fixPriceList',
		 		queryParams:{
		 			 station:$('#station').combobox("getValue")
		 		},
	    		columns:[[
	    		    {field:'set_date',title:'日期',align:'center',width:80},
					{field:'goods_id',title:'商品编号',align:'center',width:80},
					{field:'goods_name',title:'商品名称',align:'center',width:200},
					{field:'goods_kindname',title:'商品类别',align:'center',width:100},
					{field:'goods_spec',title:'商品规格（斤）',align:'center',width:100},
					{field:'sale_num',title:'当日已售数量',align:'center',width:100},
					{field:'sale_price',title:'商品当日定价/件',align:'center',width:120},
					{field:'unit_price',title:'商品当日定价/公斤',align:'center',width:120},
					{field:'sale_price0',title:'次日定价/件',width:100,align:'center',width:180,formatter: function (value,row,index){
					    var slname="sale"+index;
					    return '<input type="text" id='+slname+' name="sale" value='+row.sale_price+' />';
					}}
	 			]]
			});
		}
		
		function putaway(goods_id){
            $.post("${pageContext.request.contextPath}/goods/putAway",{goods_id:goods_id,goods_status:2},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">商品下架失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','商品下架成功！');
						$('#dg').datagrid('reload'); 
					}
				},"text");
        }
		
		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src="${pageContext.request.contextPath }"+imgUrl;
			image.setAttribute("src",src );
		}
		
		function edit(channelId){
			show("${pageContext.request.contextPath}/admin/channel/editBefore/"+channelId,"修改栏目信息");
			
		}

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}
		
		function save(){
			  var rows = $("#dg").datagrid("getRows");
			  var station_id = $('#station').combobox("getValue");
			  var postdata = new Array();
			  for(i in rows)
			  {
			      var goods_id = rows[i]["goods_id"];
				  var slsale = $('#sale'+i).val();
				  var slunit =   rows[i]["goods_spec"];
				  //alert("value:"+goods_id+"  "+slsale+"  "+slunit);
				  var para = new Object();
	              para.goods_id= goods_id;
				  para.slsale= slsale;
				  para.slunit= slunit;
				  para.station_id = station_id;
				  postdata.push(para);
			  }
			  //alert($.toJSON(postdata));
			  var para = JSON.stringify(postdata);
			  
			  $.ajax({
		    	url:"${pageContext.request.contextPath}/goods/batchSavePrice",  
			    type:"post",
	            dataType : 'json',
			    data:para,
			    success:function(data){
			       window.location.reload();
			    },
			    error : function(msg) {
			        console.info(msg);
			    }
			});
		}
		
		function findData(){
			loadTable();
		}
	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
    <table id="dg" title="商品批量定价" toolbar="#searchtool" loadMsg="正在查询..."></table>
    <div id="searchtool" style="padding:5px;height:auto;">  
       <span style="margin:0px 12px;">站点:</span><input id="station" class="easyui-textbox" style="width:180px;height:26px"/> 
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a>
       <a href="javascript:save()" class="easyui-linkbutton" data-options="iconCls:'icon-my-add'" style="width:100px;margin:0px 3px;">定价确认</a> 
    </div>
  </body>
</html>
